﻿var resourceCatalogTree = null;
var fileUploadIP = InitialParameter("/Config.json")["fileUploadOrigin"].value;
function initPage(resourceType, resourceID) {
    var thisResult = null; 
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/fuwuguanli.ashx",
        data: {
            stype: "sourceData",
            mtype: "",
            param: resourceType,
            guid: resourceID
        },
        datatype: "json",
        success: function (result) {
            if (result) {
                thisResult = JSON.parse(result)[0];
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    })
    return thisResult;
}
$(document).ready(function () {
    var resourceID = getQueryString("id");
    var resourceType = null;
    var loadMode = getQueryString("mode");
    var userInfo = getUserInfo();
    if (!userInfo) {
        console.log("登录超时或未登录，获取用户信息失败");
        return;
    }
    userInfo = userInfo[0];
    var userno = userInfo.NO;
    var orgID = userInfo.FK_DEPT;
    var pageName = getThisPageName()[0];
    var tableType = null;
    switch (pageName) {
        case "CreateDataSourceInfo":
            resourceType = 1;
            tableType = "data";
            break;
        case "CreateToolInfo":
            resourceType = 3;
            tableType = "server";
            break;
        case "CreateMapInfo":
            resourceType = 4;
            tableType = "img";
            break;
        case "CreateFileInfo":
            resourceType = 5;
            tableType = "file";
            break;
    }
    // var ResourceData = initPage(resourceType, resourceID);
    var ResourceData = null;
    var formClassName = getClassNameByType(resourceType);
    switch (loadMode) {
        case "add":
            var strCatalogData = getCatalogData();
            var jsonCatalogData = changeStrToJsonOrArray(strCatalogData, null, true, "json");
            resourceCatalogTree = getTreeCatalog(jsonCatalogData);
            $(".formSubmit").css("display", "");
            $(".formSubmit").val("保存");
            break;
        case "edit":
            $(".formSubmit").css("display", "");
            $(".formSubmit").val("保存");
            $(".formDelete").css("display", "");
            fillPageForm(resourceType, ResourceData);
            break;
        case "view":
        default:
            $(".trPositionAddress").css("display", "");
            $(".formSubmit").css("display", "none");
            $("." + formClassName).attr("disabled", "disabled");
            fillPageForm(resourceType, ResourceData);
            break;
    }
    //如果是实体类型  添加资源浏览按钮
    switch (resourceType) {
        case 1:
            if (ResourceData.JBSJLX) {
                switch (upperOrLower(ResourceData.JBSJLX)) {
                    case "shp":
                    case "mdb":
                    case "gdb":
                        $(".viewDataSource").css("display", "");
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
    //查看资源按钮
    $(".viewDataSource").click(function () {
        window.open("/MapServer/Portal/2D3DViewer.html?mode=sourcedata&guid=" + resourceID, "_parent");
    });
    //提交资源按钮
    $(".formSubmit").click(function () {
        var options = {
            type: resourceType,
            mode: loadMode,
            user: userno,
            guid: resourceID,
            orgid: orgID
        }
        clickSubmitButton(options);
    });
    //删除资源按钮
    $(".formDelete").click(function () {
        if (confirm("确定删除该资源？")) {
            if (resourceID) {
                var result1= deleteInfo(tableType, " where GUID='" + resourceID + "' ");
                var result2 = deleteInfo("resource", " where RESOURCEID='" + resourceID + "' ");
                var result3 = deleteInfo("permission", " where resource_id='" + resourceID + "' ");
                if (result1||result2) {
                    alert("删除成功！");
                    open("/BasePlatform/DataServer/" + pageName + ".html?mode=add", "_parent");
                }
                else {
                    alert("删除失败！");
                }
            }
            else {
                alert("参数错误!");
            }
        }
    });
})
//点击提交按钮
function clickSubmitButton(options) {
    var resourceType = options.type;
    var loadMode = options.mode;
    var resourceID = options.guid;
    var isOpenOptions = false;
    if (loadMode=="add") {
        isOpenOptions = true;
    }
    var $nameNode = $("input[class*=ipt_source_][name*=NAME]");
    if (trimStr($nameNode.val()) == "") {
        $nameNode = $nameNode.parent().prev().text();
        //$nameNode.replace(/\r/g, "");
        //$nameNode=$nameNode.replace(/\ +/g,"");//去掉空格
        //$nameNode=$nameNode.replace(/[ ]/g,"");    //去掉空格
        $nameNode=$nameNode.replace(/[ \r\n]/g,"");//去掉空格回车换行
        alert("[" + $nameNode + "]不能为空");
        return;
    }
    
    createOptionsWindows(isOpenOptions, function (result) {
        var formClassName = getClassNameByType(resourceType);
        var inputJson = getInputJsonByClassName(formClassName);
        inputJson["JBPXSY"] = "0";
        inputJson["PXSY"] = "0";
        inputJson["OWNER"] = options.user;
        inputJson["COMPANY"] = options.orgid;
        inputJson = jQuery.extend(inputJson, result);
        var strJson;
        var insertType = null;
        switch (resourceType) {
            case 1:
                insertType = "isInsertSourceData";
                inputJson["MSSCRQ"] = inputJson["PRODUCETIME"];
                inputJson["MSSJSCDW"] = inputJson["JBSCDW"];
                inputJson["ZYTB"] = "sourcedata.png";
                break;
            case 3:
                insertType = "isInsertSourceServer";
                inputJson["ZYTB"] = "sourcetool.png";
                break;
            case 4:
                insertType = "isInsertSourceImg";
                inputJson["BZSJ"] = inputJson["PRODUCETIME"];
                inputJson["ZYTB"] = "sourceimg.png";
                break;
            case 5:
                insertType = "isInsertSourceFile";
                inputJson["BZSJ"] = inputJson["PRODUCETIME"];
                inputJson["ZYTB"] = "sourcefile.png";
                break;
        }
        //if (trimStr(resourceType == 1 ? inputJson["JBNAME"] : inputJson["NAME"]) == "") {
        //    alert("资源名不能为空");
        //    return;
        //}
        switch (loadMode) {
            case "add":
                inputJson["GUID"] = getGUID();
                //if (resourceType == 3) {
                //    inputJson["GUID"] = inputJson["GUID"] + "_2";
                //}
                strJson = getStrByJson(inputJson);
                insertSource(insertType, strJson);
                break;
            case "edit":
                inputJson["GUID"] = resourceID;
                strJson = getStrByJson(inputJson);
                updateSource(resourceType.toString(), strJson);
                break;
            default: break;
        }
        console.log(inputJson);
    });
}
//获取页面名
function getThisPageName() {
    var a = location.href;
    var b = a.split("/");
    var c = b.slice(b.length - 1, b.length).toString(String).split(".");
    return c.slice(0, 1);
}
//填充页面表单
function fillPageForm (resourceType, ResourceData) {
    var formClassName = getClassNameByType(resourceType);
    for (var key in ResourceData) {
        $("input[class*="+formClassName+"][name*=" + key + "]").val(ResourceData[key]);
        $("textarea[class*="+formClassName+"][name*=" + key + "]").val(ResourceData[key]);
    }

    //填充服务地址
    $(".trPositionAddress input").val("\\\\" + ResourceData.IP + ResourceData.ADDRESS);

    switch (resourceType) {
        case 4:
        case "4":
            var pathArray = ResourceData.ADDRESS.split("\\");
            var filePath = pathArray[pathArray.length - 2] + "/" + pathArray[pathArray.length - 1];
            var fileUrl = "http://" + fileUploadIP + "/sw/upload/resourceDownload?fileName=" + filePath;
            $("#ViewImg_Img,#ViewImg_ZoomOut").click(function () {
                open("/BasePlatform/ModelDriven/showImg.html?file=" + encodeURIComponent(fileUrl), "_blank");
            });
            return;
            //// 填充图片
            //$('#ViewImg_Img').attr('src', ResourceData.ADDRESS);
            //// 全屏
            //$('#ViewImg_ZoomOut').attr('href', ResourceData.ADDRESS);

            break;
        default:
            return;
            break;
    }
}
//根据类型获取classname
function getClassNameByType(type) {
    var formClassName = null;
    switch (type) {
        case 1:
            formClassName = "ipt_source_data";
            break;
        case 3:
            formClassName = "ipt_source_server";
            break;
        case 4:
            formClassName = "ipt_source_img";
            break;
        case 5:
            formClassName = "ipt_source_file";
            break;
    }
    return formClassName;
}

//根据类名读取输入信息返回json
function getInputJsonByClassName(classname) {
    var nodes = document.getElementsByClassName(classname);
    var node = null;
    var nodeName = null;
    var thisResult = {};
    for (var i = 0; i < nodes.length; i++) {
        node = nodes[i];
        nodeName = node.attributes.name.value;
        thisResult[nodeName] = node.value;
    }
    return thisResult;
}
//json转字符串
function getStrByJson(json) {
    return JSON.stringify(json);
}
//插入资源信息
function insertSource(type, strJson) {
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: type,
                strjson: strJson
            },
        datatype: "json",
        success: function (result) {
            if (result == "True") {
                alert("插入成功！");
                open("/BasePlatform/DataServer/dataserver.html?id=create&serverType=menu", "_parent");
            }
            else {
                alert("插入失败！");
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
}
//更新资源信息
function updateSource(type, strJson) {
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "isUpdateSource",
                type:type,
                strjson: strJson
            },
        datatype: "json",
        success: function (result) {
            if (result == "True") {
                alert("更新成功！");
            }
            else {
                alert("更新失败！");
            }
        }
    });
}
//删除信息
function deleteInfo(dataType, strWhere) {
    var thisResult = false;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "DeleteInfo",
                datatype: dataType,
                strwhere: strWhere
            },
        datatype: "json",
        success: function (result) {
            if (result == "True") {
                thisResult = true;
            }
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisResult;
}

//生成四类资源公共选项窗口
function createOptionsWindows(isOpenOptions, callback) {
    if (!isOpenOptions) {
        callback({});
        return;
    }
    var div_mengBan = document.createElement("div");
    div_mengBan.className = "div_mengBan";
    document.body.appendChild(div_mengBan);
    $(".div_mengBan").height($(window).height());
    $(".div_mengBan").width($(window).width());


    var div_publicOptions = document.createElement("div");
    div_publicOptions.className = "div_publicOptions";
    $(div_publicOptions).css('left', (($(window).width() - 900) / 2) + "px").css('top', (($(window).height() - 325) / 2) + "px")
    var table_pulicOptions = document.createElement("table");
    table_pulicOptions.className = "table_pulicOptions";

    //头
    var tr_optionsHead = document.createElement("tr");
    tr_optionsHead.className = "publicOptionsHead";
    tr_optionsHead.innerHTML = "<td colspan='5'>&nbsp&nbsp完善资源信息</td>";
    table_pulicOptions.appendChild(tr_optionsHead);

    //内容
    //资源类型
    var tr_optionsResourceType = document.createElement("tr");
    tr_optionsResourceType.className = "publicOptionsContent publicOptionsResourceType";
    tr_optionsResourceType.innerHTML = "<td class='firstCell' style='width:16%;'>资源类型</td>"
        + "<td style='width:21%;'><select id='selectAttrA'><option value='null'>请选择资源类型</option></select></td>"
        + "<td style='width:21%;'><select id='selectAttrB'><option value='null'>请选择资源类型</option></select></td>"
        + "<td style='width:21%;'><select id='selectAttrC'><option value='null'>请选择资源类型</option></select></td>"
        + "<td style='width:21%;'><select id='selectAttrD'><option value='null'>请选择资源类型</option></select></td>";
    table_pulicOptions.appendChild(tr_optionsResourceType);

    //所属区域
    var tr_optionsResourceArea = document.createElement("tr");
    tr_optionsResourceArea.className = "publicOptionsContent publicOptionsArea";
    tr_optionsResourceArea.innerHTML = "<td class='firstCell'>所属区划</td>"
        + "<td><select id='selectAreaA'><option value='null'>请选择行政区划</option></select></td>"
        + "<td><select id='selectAreaB'><option value='null'>请选择行政区划</option></select></td>"
        + "<td><select id='selectAreaC'><option value='null'>请选择行政区划</option></select></td>";
    table_pulicOptions.appendChild(tr_optionsResourceArea);

    //存储位置输入
    var tr_optionsPosition1 = document.createElement("tr");
    tr_optionsPosition1.className = "publicOptionsContent publicOptionsPosition1";
    tr_optionsPosition1.innerHTML = "<td class='firstCell'>服务器</td>"
        + "<td><select id='selectPositionA'><option value='null'>请选择服务器</option></select></td>"
        + "<td class='firstCell'>地址</td>"
        + "<td colspan='2' style='text-align:left;'><input type='text' class='iptText' id='selectPositionB' value=''/><a href='javascript:void(0)' id='selectPosition_select'>选择</a></td>";
    table_pulicOptions.appendChild(tr_optionsPosition1);
    //存储位置选择
    var tr_optionsPosition2 = document.createElement("tr");
    tr_optionsPosition2.className = "publicOptionsContent publicOptionsPosition2";
    tr_optionsPosition2.style.display = "none";
    tr_optionsPosition2.innerHTML = "<td class='firstCell'>服务器</td><td colspan='4'><input type='text' class='iptText' id='selectFilePath' disabled='disabled' style='width:91%'/><a href='javascript:void(0)' id='selectPosition_ipt'>输入</a><input id='fileUpload' style='display:none;' type='file' value='' /></td>";
    table_pulicOptions.appendChild(tr_optionsPosition2);

    //专题、编制时间
    var tr_optionsQTA = document.createElement("tr");
    tr_optionsQTA.className = "publicOptionsContent publicOptionsQTA";
    tr_optionsQTA.innerHTML = "<td class='firstCell'>所属专题</td>"
        + "<td><select id='selectSpatial'><option value='null'>请选择专题分类</option></select></td>"
        + "<td class='firstCell'>编制时间</td>"
        + "<td colspan='2' style='text-align:left;'><input type='date' class='iptText' id='selectBZSJ'/></td>";
    table_pulicOptions.appendChild(tr_optionsQTA);



    //确定、取消
    var tr_optionsBtn = document.createElement("tr");
    tr_optionsBtn.className = "publicOptionsContent publicOptionsBtn";
    tr_optionsBtn.innerHTML = "<td style='text-align:right;' colspan='5'>"
        + "<input type='button' value='确定' class='iptButton' id='btnSubmit'/>"
        + "<input type='button' value='取消' class='iptButton' id='btnCancel'/></td>";
    table_pulicOptions.appendChild(tr_optionsBtn);

    div_publicOptions.appendChild(table_pulicOptions);
    document.body.appendChild(div_publicOptions);

    $("#btnCancel").click(function () {
        $(div_mengBan).remove();
        $(div_publicOptions).remove();
    });

    $("#btnSubmit").click(function () {
        var XZQHDM = $("#selectAreaC").val() == "null" ? ($("#selectAreaB").val() == "null" ? $("#selectAreaA").val() + "0000" : $("#selectAreaB").val() + "00") : $("#selectAreaC").val();
        var POSITION = null;
        var ADDRESS = null;
        if ($(".publicOptionsPosition1").css("display")=="none") {
            var dataPosition = $("#selectFilePath").val();
            if (dataPosition) {
                dataPosition = dataPosition.split("\\\\")[1];
                var firstXieXian = dataPosition.indexOf("\\");
                POSITION = dataPosition.slice(0, firstXieXian);
                POSITION = $("#selectPositionA option[address='" + POSITION + "']").attr("value");
                ADDRESS = dataPosition.slice(firstXieXian);
                if (!POSITION) {
                    alert("地址入库解析失败，请添加共享文件夹连接");
                    return;
                }
            }
            else {
                alert("请选择需要上传的文件");
                return;
            }
        }
        else {
            POSITION = $("#selectPositionA").val();
            ADDRESS = $("#selectPositionB").val();
        }
        var optionsData = {
            "ATTR_A": $("#selectAttrA").val(),
            "ATTR_B": $("#selectAttrB").val()=="null"?"":$("#selectAttrB").val(),
            "ATTR_C": $("#selectAttrC").val() == "null" ? "" : $("#selectAttrC").val(),
            "ATTR_D": $("#selectAttrD").val() == "null" ? "" : $("#selectAttrD").val(),
            "ATTR_E": "",
            "ATTR_F": "",
            "ATTR_G": "",
            "ATTR_H": "",
            "ATTR_I": "",
            "ATTR_J": "",
            "AREA": XZQHDM,
            "POSITION": POSITION,
            "ADDRESS": ADDRESS,
            "SPATIAL": $("#selectSpatial").val(),
            "PRODUCETIME": $("#selectBZSJ").val(),
            "YEAR": $("#selectBZSJ").val() == "" ? new Date().getFullYear(): $("#selectBZSJ").val().split("-")[0]
        }
        optionsData["PRODUCETIME"] = optionsData["PRODUCETIME"] == "" ? getTimeNow("d").replace(/\//g,'-') : optionsData["PRODUCETIME"];
        callback(optionsData);
        $(div_mengBan).remove();
        $(div_publicOptions).remove();
    });

    //切换资源位置选择或输入
    $("#selectPosition_select").click(function (evt) {
        var trNode = $(evt.currentTarget).parent().parent();
        trNode.css("display", "none");
        trNode.next().css("display", "");

        $("#fileUpload").click();
    });
    $("#selectPosition_ipt").click(function (evt) {
        var trNode = $(evt.currentTarget).parent().parent();
        trNode.css("display", "none");
        trNode.prev().css("display", "");
    });
    $("#fileUpload").change(function () {
        var file = this.files[0];
        var formData = new FormData();
        formData.append("file", file);
        formData.append("path", getUser()+"/");"admin/"
        var url = "http://"+fileUploadIP+"/sw/upload/resourceSingleUpload";
        $.ajax({
            type: 'post',
            url: url,
            cache: false,
            contentType: false,
            processData: false, //默认为true，默认情况下，发送的数据将被转换为对象，设为false不希望进行转换
            data: formData, //数据

            success: function (res, textStatus, jqXHR) {
                //$("#selectFilePath").val("\\\\192.168.100.229\\admin\\points.json");
                var result = JSON.parse(res);
                if (result.code == "200") {
                    $("#selectFilePath").val(result.data);
                }
                else {
                    alert(result.msg+"[error:"+result.code+"]");
                }
            },
            error: function (err) {
                console.log(err);
                //$this.parent().find('.uploaded').html('');
            }
        });
        getNodeByID("fileUpload").value = null;
        return;
        //上传文件
        var file = this.files[0];
        var form = new FormData();
        form.append("stype", "uploadFile"); //实际业务的其他请求参数
        form.append("file", file); //第一个参数是后台读取的请求key值
        form.append("userno", getUser());
        form.append("fileName", file.name);
        var xhr = new XMLHttpRequest();
        var action = "/BaseAshx/Upload/Upload.ashx"; //上传服务的接口地址
        xhr.open("POST", action);
        xhr.send(form); //发送表单数据
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                $("#selectFilePath").val(xhr.responseText);
                //if (xhr.responseText == "False") {
                //    $(".file_upload_layer_ZYTB").val("fuw.jpg");
                //    $(".file_upload_arcgis_ZYTB").val("fuw.jpg");
                //    isTransit = false;
                //    alert("文件格式错误");
                //}
                //else {
                //    $(".file_upload_layer_ZYTB").val(xhr.responseText);
                //    $(".file_upload_arcgis_ZYTB").val(xhr.responseText);
                //    isTransit = true;
                //}
                //var resultObj = JSON.parse(xhr.responseText);//处理返回的数据......
            }
        };
        getNodeByID("fileUpload").value = null;
    });
    //工具类型隐藏位置选择
    if (getPageName() == "CreateToolInfo.html") {
        $("#selectPosition_select").css("display", "none");
    }

    //资源类型下拉框
    fillResourceTypeSelect();
    fillResourceTypeSelect(2);
    $("#selectAttrA").change(function () {
        fillResourceTypeSelect(2);
        $("#selectAttrC").empty();
        $("#selectAttrC").append("<option value='null'>请选择资源类型</option>");
        $("#selectAttrD").empty();
        $("#selectAttrD").append("<option value='null'>请选择资源类型</option>");
    });
    $("#selectAttrB").change(function () {
        fillResourceTypeSelect(3);
        $("#selectAttrD").empty();
        $("#selectAttrD").append("<option value='null'>请选择资源类型</option>");
    });
    $("#selectAttrC").change(function () {
        fillResourceTypeSelect(4);
    });

    //行政区划下拉框
    fillXZQHSelect();
    $("#selectAreaA").val('15');//默认选中内蒙古自治区
    fillXZQHSelect(2);
    $("#selectAreaA").change(function () {
        fillXZQHSelect(2);
        $("#selectAreaC").empty();
        $("#selectAreaC").append("<option value='null'>请选择行政区划</option>");
    })
    $("#selectAreaB").change(function () {
        fillXZQHSelect(3);
    })

    //服务器下拉框
    fillPositionSelect();

    //专题下拉框
    fillSpatialSelect();

    //默认选中索引为0项
    $("select option:first").prop("selectIndex", 0);
}
//调整蒙版大小
function changeMengBanSize() {
    $(".div_mengBan").height($(window).height());
    $(".div_mengBan").width($(window).width());
    $(".div_publicOptions").css('left', (($(window).width() - 900) / 2) + "px").css('top', (($(window).height() - 325) / 2) + "px")
}

//填充资源类型下拉框
function fillResourceTypeSelect(selectIndex) {
    var attrA = $("#selectAttrA").val();
    var attrB = $("#selectAttrB").val();
    var attrC = $("#selectAttrC").val();
    var attrD = $("#selectAttrD").val();
    var selectDatas = null;
    var selectId = null;
    switch (selectIndex) {
        case 2:
            selectDatas = resourceCatalogTree[attrA];
            selectId = "selectAttrB";
            break;
        case 3:
            selectDatas = resourceCatalogTree[attrA][attrB];
            selectId = "selectAttrC";
            break;
        case 4:
            selectDatas = resourceCatalogTree[attrA][attrB][attrC];
            selectId = "selectAttrD";
            break;
        case 1:
        default:
            selectDatas = resourceCatalogTree;
            selectId = "selectAttrA";
            break;
    }
    $("#" + selectId).empty();
    if (selectId != "selectAttrA") {
        if (getJsonLength(selectDatas) == 0) {
            $("#" + selectId).append("<option value='null'>暂无分类</option>");
            return;
        }
        else {
            $("#" + selectId).append("<option value='null'>请选择资源类型</option>");
        }
    }
    for (var key in selectDatas) {
        $("#" + selectId).append("<option value='" + key + "'>" + key + "</option>");
    }
}
//从数据库读取资源目录数据
function getCatalogData() {
    var thisresult;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Resource/ResourceAshx.ashx",
        data: //发送到服务器的参数
            {
                stype: "getResourceTree"
            },
        datatype: "json",
        success: function (result) {
            thisresult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    return thisresult;
}
//获取资源目录树结构数据
function getTreeCatalog(CatalogTreeData) {
    var thisResult = {};
    var attrArr = ["ATTR_A", "ATTR_B", "ATTR_C", "ATTR_D", "ATTR_E", "ATTR_F", "ATTR_G", "ATTR_H", "ATTR_I", "ATTR_J"];
    var attrone;
    var catalogone;
    for (var key in CatalogTreeData) {
        catalogone = CatalogTreeData[key];
        if (catalogone["ATTR_A"] != "") {
            if (!thisResult[catalogone["ATTR_A"]]) {
                thisResult[catalogone["ATTR_A"]] = {};
            }
            if (catalogone["ATTR_B"] != "") {
                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]]) {
                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]] = {};
                }
                if (catalogone["ATTR_C"] != "") {
                    if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]]) {
                        thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]] = {};
                    }
                    if (catalogone["ATTR_D"] != "") {
                        if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]]) {
                            thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]] = {};
                        }
                        if (catalogone["ATTR_E"] != "") {
                            if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]]) {
                                thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]] = {};
                            }
                            if (catalogone["ATTR_F"] != "") {
                                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]]) {
                                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]] = {};
                                }
                                if (catalogone["ATTR_G"] != "") {
                                    if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]]) {
                                        thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]] = {};
                                    }
                                    if (catalogone["ATTR_H"] != "") {
                                        if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]]) {
                                            thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]] = {};
                                        }
                                        if (catalogone["ATTR_I"] != "") {
                                            if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]]) {
                                                thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]] = {};
                                            }
                                            if (catalogone["ATTR_J"] != "") {
                                                if (!thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]][catalogone["ATTR_J"]]) {
                                                    thisResult[catalogone["ATTR_A"]][catalogone["ATTR_B"]][catalogone["ATTR_C"]][catalogone["ATTR_D"]][catalogone["ATTR_E"]][catalogone["ATTR_F"]][catalogone["ATTR_G"]][catalogone["ATTR_H"]][catalogone["ATTR_I"]][catalogone["ATTR_J"]] = {};
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return thisResult;
}

//填充行政区下拉框
function fillXZQHSelect(selectIndex) {
    var selectSheng = $("#selectAreaA").val();
    var selectShi = $("#selectAreaB").val();
    var selectXian = $("#selectAreaC").val();

    var selectId = null;
    var XZQHDatas;
    switch (selectIndex) {
        case 2:
            XZQHDatas = getLowerXZQH(selectSheng);
            selectId = "selectAreaB";
            break;
        case 3:
            XZQHDatas = getLowerXZQH(selectShi);
            selectId = "selectAreaC";
            break;
        case 1:
        default:
            XZQHDatas = getLowerXZQH(null);
            selectId = "selectAreaA";
            break;
    }
    var XZQHData = null;
    $("#" + selectId).empty();
    if (selectId != "selectAreaA") {
        $("#" + selectId).append("<option value='null'>请选择行政区划</option>");
    }
    for (var key in XZQHDatas) {
        XZQHData = XZQHDatas[key];
        $("#" + selectId).append("<option value='" + XZQHData.XZQDM + "'>" + XZQHData.XZQMC + "</option>");
    }
}
//获取行政区划
function getLowerXZQH(XZQDM) {
    var thisResult = null;
    $.ajax({
        type: "post",
        async: false,
        url: "/BaseAshx/Map/DataServer.ashx",
        data: //发送到服务器的参数
            {
                stype: "getXZQHData",
                xzqdm: XZQDM
            },
        datatype: "json",
        success: function (result) {
            thisResult = result;
        },
        error: function (err) {
            if (err.status == 405)
                top.location.href = '/';
        }
    });
    thisResult = changeStrToJsonOrArray(thisResult, null, true, "json");
    return thisResult;
}

//填充服务器下拉框
function fillPositionSelect() {
    var positionDatas = getSpecialDataDict("position4");
    $("#selectPositionA").empty();
    var positionData = null;
    for (var key in positionDatas) {
        positionData=positionDatas[key];
        $("#selectPositionA").append("<option address='" + positionData.ZDVALUE + "' value='" + positionData.ZDTITLE + "' title='" + positionData.ZDVALUE + "'>" + positionData.ZDTITLE + "</option>")
    }
}

//填充专题下拉框
function fillSpatialSelect() {
    var spatialDatas = getDataDict("spatial");
    $("#selectSpatial").empty();
    var spatialData = null;
    for (var key in spatialDatas) {
        spatialData=spatialDatas[key];
        $("#selectSpatial").append("<option value='" + spatialData.ZDVALUE + "' title=''>" + spatialData.ZDTITLE + "</option>")
    }
}

////预览资源
//function clickViewResource(node) {
//    var address = $(node).prev().val();
//    //address = address.replace(/\\/g, "/");
//    //address = address.replace(/localhost/g, "192.168.100.111");
//    //address="file:"+address;
//    //console.log(address);
//    //open(address, "_blank");
//    //window.open(address);


//    //var command = "\\\\192.168.1.155\\share\\" + command;
//    //window.oldOnError = window.onerror;
//    //window._command = address;
//    //window.onerror = function (err) {
//    //    if (err.indexOf('automation') != -1) {
//    //        alert("命令" + window._command + "已经被用户禁止!");
//    //        return true;
//    //    }
//    //    else return false;
//    //}
//    //var wsh = new ActiveXObject("WScript.Shell");
//    //if (wsh) {
//    //    wsh.Run(address);
//    //}
//    //https://www.cnblogs.com/mophy/p/10521812.html
//    //window.onerror = window.oldOnError;
//}
